<?php
class IndexController extends Zendvn_Controller_Action{
	
public function indexAction(){
		
		$this->view->module = "home";
		
		$categoryid = @$this->_request->getParam('categoryid');
		
		$this->view->main = TRUE;
		
		$post = new Post_Model_Index();
		
		$this->view->media = new Post_Model_Media();
		
		$page = 1;
		
		$pagesize = 12;
		
		
		$this->view->categoryid = $categoryid;		
		
		$status = "publish";
		
		$storage = new Zend_Auth_Storage_Session();
		$data = $storage->read();
		
		if(isset($data) && $categoryid == ""){
			
			$arr = array(
			"userfeedid"=>$data->id,
			"categoryid"=>$categoryid,										
			"status"=>$status,	
			"page"=> $page,
			"pagesize"=> $pagesize,																			
			);
			
			$total  = $post->countPostFeed($arr);
			
			$arr = array(
			"userfeedid"=>$data->id,
			"page"=> $page,
			"pagesize"=> $pagesize,
			"total"=> $total,
			);
			
			$this->view->posts = $post->listFeed($arr);
		}
		else{
			
			$arr = array(
			"categoryid"=>$categoryid,										
			"status"=>$status,	
			"page"=> $page,
			"pagesize"=> $pagesize,																			
			);
			
			$total  = $post->countPostHome($arr);
			
			$arr = array(
			"categoryid"=>$categoryid,										
			"status"=>$status,	
			"page"=> $page,
			"pagesize"=> $pagesize,
			"total"=> $total,																
			);
			$this->view->posts = $post->listItemAll($arr);	
		}
			
		
		
		
		
		$this->view->post = $post;
		
		$this->view->total = $total;
		$this->view->page = $page +1;
		$this->view->pagesize = $pagesize;
		
		$this->view->pagecomment = 1;			
		$this->view->pagesizecomment = 3;	
		$this->view->comment = new Post_Model_Comment();
		
		$this->view->auth = new Registration_Model_Auth();
		
		$this->view->like = new Post_Model_Like();
		
		$this->view->follow = new Registration_Model_Follow();
		
		$chanel = new Chanel_Model_Index();
		$page = 1;		
		$pagesize = 10;
		$arr = array(				
			"page"=> $page,
			"pagesize"=> $pagesize,
			"userid"=> @$data->id,
																
		);
		
		$this->view->countChanel = $chanel->countItem($arr);
		
	}
	
	public function ajaxposthomeAction(){
		
		$this->view->main = FALSE;		
		
		if($this->getRequest()->isPost()){
			
			$storage = new Zend_Auth_Storage_Session();
			$data = $storage->read();
		
			$page = $_POST["page"];
			$pagesize = $_POST["pagesize"];
			$total = $_POST["total"];
			$categoryid = @$_POST["categoryid"];
			
			
			$post = new Post_Model_Index();		
			
			
			$media = new Post_Model_Media();
					
			$comment = new Post_Model_Comment();
			
			$auth = new Registration_Model_Auth();
			
			$like = new Post_Model_Like();
			
			$this->view->pagecomment = 1;
			
			$this->view->pagesizecomment = 5;	
			
			
			if (isset($page) && isset($pagesize) && isset($total)){
				
				$status = "publish";
		
				
				
				if(isset($data)){
					
					$arr = array(
					"userfeedid"=>$data->id,
					"categoryid"=>$categoryid,										
					"status"=>$status,	
					"page"=> $page,
					"pagesize"=> $pagesize,																			
					);
			
					$total  = $post->countPostFeed($arr);
					
						
					$arr = array(
					"userfeedid"=>$data->id,
					"page"=> $page,
					"pagesize"=> $pagesize,
					"total"=> $total,
					);
						
						$this->view->posts = $post->listFeed($arr);
				}else {
					
					$arr = array(			
						"categoryid"=>$categoryid,							
						"status"=>$status,	
						"page"=> $page,
						"pagesize"=> $pagesize,																
					);
					
				
			
					$total  = $post->countPostHome($arr);
					
					$arr = array(			
							"categoryid"=>$categoryid,							
							"status"=>$status,	
							"page"=> $page,
							"pagesize"=> $pagesize,
							"total"=> $total,																
					);
					
					$this->view->posts = $post->listItemAll($arr);
				
				}
					
				$this->view->post = $post;
				
				$this->view->media = $media;
					
				$this->view->comment = $comment;
				
				$this->view->auth = $auth;
				
				$this->view->like = $like;
								
			}
			
						
		}
		
		
	}
	
}